package com.ocom.ugcapi.mq.consumer;

import com.google.gson.Gson;
import com.ocom.common.vo.pay.CheckVo;
import com.ocom.ugcapi.service.PayService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/7/3
 **/
@Slf4j
@Component
public class ActiveQuiryConsumer {


	@Autowired
	PayService payService;

	@RabbitHandler
	@RabbitListener(queues = "dead-active-check-message-queue")
	public void listenDelayQueue(Message message, @Headers Map<String, Object> headers, Channel channel) throws IOException {


		System.out.println("延时队列接收到消息:" + message);

		try {
			Gson gson=new Gson();
			String se = new String(message.getBody(), "UTF-8");
			CheckVo checkVo= gson.fromJson(se,CheckVo.class);
			payService.check(checkVo.getCompanyId(),checkVo.getOutTradeNo());
		}catch (Exception e){
			log.info("查询队列异常 【{}】 ",e);
		}

		//确认接收消息
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
	}
}
